use std::cmp::Ordering;
use std::io;

use rand::Rng;

pub fn main() {
    let secret_number = rand::thread_rng().gen_range(1, 101);
    // println!("神秘数字是：{}", secret_number);


    loop {
        println!("猜测一个数");
        let mut guress = String::new();
        io::stdin().read_line(&mut guress).expect("无法读取行");

        // let guess: u32 = guress.trim().parse().expect("你输入的数字不合法");
        let guess: u32 = match guress.trim().parse() {
            Ok(num) => num,
            Err(_) => {
                println!("您输入的数字不合法");
                continue;
            }
        };

        println!("你猜测的数是：{}", guress);

        match guess.cmp(&secret_number) {
            Ordering::Less => println!("太小了"),
            Ordering::Greater => println!("太大了"),
            Ordering::Equal => {
                println!("你赢了");
                break;
            }
        }
    }
}
